package com.jinsi.controller.tang;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jinsi.constant.YltConstant;
import com.jinsi.pojo.Journal;
import com.jinsi.service.tang.JournalService;
import com.jinsi.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 查看商品日志列表
 * @author 唐文博
 * @Date 2022-08-09
 */
@RestController
@RequestMapping("/journal")
@Slf4j
public class JournalController {
    @Autowired
    private JournalService journalService;

    /**
     * 查看表，全查，分页
     * @param page
     * @param limit
     * @param journalName
     * @param journalOperationList
     * @param journalOperation
     * @param timeTable
     * @return
     */
    @RequestMapping("/getJournalSee")
    public R getJournalSee(Integer page, Integer limit, String journalName,
                                            String journalOperationList,
                                            String journalOperation, String timeTable) {
        PageHelper.startPage(page, limit);
        List<Journal> list = journalService.getJournalSee(journalName,journalOperationList,
                journalOperation,timeTable);
        PageInfo<Journal> pageInfo = new PageInfo<>(list);
        return R.custom(YltConstant.LAYUI_CODE,
                YltConstant.LAYUI_MSG,
                pageInfo.getList(),
                pageInfo.getTotal());
    }

    /**
     *  删除接口
     * @param journalId
     * @return
     */
    @RequestMapping("/journalDelete")
    public R journalDelete(Integer journalId) {
        try {
            log.info("删除商品日志: [开始], 商品日志id:{}",journalId);
            journalService.deleteJournal(journalId);
            log.info("删除商品日志: [结束] 结果：{}","成功");
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            log.error("删除商品日志: [失败]", e);
            return R.error();
        }
    }
}
